package com.wuyangnju.healthclub.service;

import java.util.List;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.wuyangnju.healthclub.dao.FamilyDao;
import com.wuyangnju.healthclub.dao.SingleDao;
import com.wuyangnju.healthclub.entity.Family;
import com.wuyangnju.healthclub.entity.Single;
import com.wuyangnju.healthclub.util.VirDate;

@Component
public class TimeService {
	@PersistenceContext
	private EntityManager em;

	@Resource
	private SingleDao singlePersonDao;

	@Resource
	private FamilyDao familyDao;

	@Resource
	private FinancialService finacialService;

	@Transactional
	public void NextNewMonth() {
		VirDate.get().oneMonthPassBy();

		List<Single> singlePersons = singlePersonDao.retrieve(em);
		for (Single singlePerson : singlePersons) {
			finacialService.singlePay(singlePerson.getCardId());
		}
		List<Family> familys = familyDao.retrieve(em);
		for (Family family : familys) {
			finacialService.familyPay(family.getCardId());
		}
	}

	public void NextDay() {
		VirDate.get().oneDayPassBy();
	}
}